<template>
	<view class="mineCommunity">
		<app-title titleBackground="#8D84FF" @leftClick='backFun' :lefticonSize='30' text="我的社区"
			color="#fff"></app-title>
		<view class="mineCommunity_box">
			<view class="mineCommunity_box_scroll">
				<view class="mineCommunity_box_scroll_top">
					<view class="mineCommunity_box_scroll_top_centrer">
						<image class="mineCommunity_box_scroll_top_centrer_image"
							:src="res.avatar?'':'../../../static/logo.png'" mode=""></image>
						<view class="mineCommunity_box_scroll_top_centrer_xinxi">
							<p>{{res.realname}}</p>
							<view class="mineCommunity_box_scroll_top_centrer_xinxi_dengji">
								<image class="mineCommunity_box_scroll_top_centrer_xinxi_dengji_img"
									src="../../../static/mine/LV.png" mode=""></image>
								{{res.levelname}}
							</view>
						</view>
						<view class="mineCommunity_box_scroll_top_centrer_id">
							<p>ID：{{res.id}}</p>
							<p>{{res.mobile}}</p>
						</view>
					</view>
					<view class="mineCommunity_box_scroll_top_centrer">
						<view class="mineCommunity_box_scroll_top_centrer_image" style="background-color: none;">

						</view>
						<view class="mineCommunity_box_scroll_top_centrer_xinxis">
							<span>我的业绩</span>
							<p>{{res.zsyj}}</p>
						</view>
					</view>
				</view>
				<view class="mineCommunity_box_scroll_wodedingdan">
					<view class="mineCommunity_box_scroll_wodedingdan_">
						<view class="mineCommunity_box_scroll_wodedingdan_item">
							<p>总业绩</p>
							<text>{{res.zyj}}</text>
						</view>
						<view class="mineCommunity_box_scroll_wodedingdan_item">
							<p>当日业绩</p>
							<text>{{res.today_yeji}}</text>
						</view>
					</view>
					<view class="mineCommunity_box_scroll_wodedingdan_">
						<view class="mineCommunity_box_scroll_wodedingdan_item">
							<p>会员人数</p>
							<text>{{res.sanxia_suoyou}}</text>
						</view>
						<view class="mineCommunity_box_scroll_wodedingdan_item">
							<p>有效会员</p>
							<text>{{res.fensi_youxiao}}</text>
						</view>
					</view>
				</view>

				<view class="mineCommunity_box_dictyosome">
					<view class="mineCommunity_box_dictyosome_item" v-for="(item,index) in list" :key="index">
						<view class="mineCommunity_box_dictyosome_item_main">
							<view class="mineCommunity_box_dictyosome_item_main_top">
								<p>{{item.levelname}} ID：{{item.id}}</p>
								<image @click.stop="openFun(index)"
									:src="item.isOpen?'../../../static/mine/kai.png':'../../../static/mine/guan.png'"
									mode="heightFix">
								</image>
							</view>
							<view class="mineCommunity_box_dictyosome_item_main_">
								<view class="mineCommunity_box_dictyosome_item_main_item">
									<p>总业绩</p>
									<span>{{item.zsyj}}</span>
								</view>
								<view class="mineCommunity_box_dictyosome_item_main_item">
									<p>当日业绩</p>
									<span>{{item.today_yeji}}</span>
								</view>
								<view class="mineCommunity_box_dictyosome_item_main_item"
									style="display: flex;justify-content: space-around;flex-direction: row;"
									:style="item.zsyj === 0?'':'color:#8A81FF;'">
									<view style="width: 30rpx;height: 30rpx;border-radius: 30rpx;"
										:style="item.zsyj === 0?'border:1rpx solid #ccc;':'background-color:#8A81FF;'">
									</view>
									{{item.zsyj === 0?'本人未下单':'本人已下单'}}
								</view>
							</view>
							<view class="mineCommunity_box_dictyosome_item_main_">
								<view class="mineCommunity_box_dictyosome_item_main_item">
									<p>无效会员</p>
									<span>{{item.wx_num}}人</span>
								</view>
								<view class="mineCommunity_box_dictyosome_item_main_item">
									<p>有效会员</p>
									<span>{{item.yx_num}}人</span>
								</view>
								<view class="mineCommunity_box_dictyosome_item_main_item">
									<p>本人消费</p>
									<span>{{item.zsyj}}</span>
								</view>
							</view>
						</view>
						<view class="mineCommunity_box_dictyosome_item_null"
							v-if="item.ChildList.length === 0 && item.isOpen">
							暂无数据
						</view>
						<view class="mineCommunity_box_dictyosome_item_Child"
							v-if="item.ChildList.length !== 0 && item.isOpen">
							<view class="mineCommunity_box_dictyosome_item_main" style="margin: 20rpx 0;"
								v-for="(items,indexs) in item.ChildList" :key="indexs">
								<view class="mineCommunity_box_dictyosome_item_main_top">
									<p>{{items.levelname}} ID：{{items.id}}</p>
								</view>
								<view class="mineCommunity_box_dictyosome_item_main_">
									<view class="mineCommunity_box_dictyosome_item_main_item">
										<p>总业绩</p>
										<span>{{items.zsyj}}</span>
									</view>
									<view class="mineCommunity_box_dictyosome_item_main_item">
										<p>当日业绩</p>
										<span>{{items.today_yeji}}</span>
									</view>
									<view class="mineCommunity_box_dictyosome_item_main_item"
										style="display: flex;justify-content: space-around;flex-direction: row;"
										:style="items.zsyj === 0?'':'color:#8A81FF;'">
										<view style="width: 30rpx;height: 30rpx;border-radius: 30rpx;"
											:style="items.zsyj === 0?'border:1rpx solid #ccc;':'background-color:#8A81FF;'">
										</view>
										{{items.zsyj === 0?'本人未下单':'本人已下单'}}
									</view>
								</view>
								<view class="mineCommunity_box_dictyosome_item_main_">
									<view class="mineCommunity_box_dictyosome_item_main_item">
										<p>无效会员</p>
										<span>{{items.wx_num}}人</span>
									</view>
									<view class="mineCommunity_box_dictyosome_item_main_item">
										<p>有效会员</p>
										<span>{{items.yx_num}}人</span>
									</view>
									<view class="mineCommunity_box_dictyosome_item_main_item">
										<p>本人消费</p>
										<span>{{items.zsyj}}</span>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import appTitle from '@/components/appTitle.vue';
	import {
		member,
		member_mycommunity
	} from "@/api/mine.js";

	export default {
		components: {
			appTitle
		},
		data() {
			return {
				openid: '',
				res: '',
				list: []
			};
		},
		onShow() {
			this.list = [];
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data;
					this.member_mycommunityFun();
				},
				fail: () => {
					uni.reLaunch({
						url: '/pages/login/login'
					});
				}
			});
		},
		methods: {
			openFun(i) {
				this.list[i].isOpen = !this.list[i].isOpen;

				console.log(this.list);
				if (this.list[i].ChildList.length === 0) {
					this.member_mycommunityFun(this.list[i].openid, i)
				}
			},
			async member_mycommunityFun(openid = '', i) {
				let up = {
					openid: openid === '' ? this.openid : openid
				}
				let data = await member_mycommunity(up);

				if (openid === '') {
					this.res = data;
					data.user_list.forEach(i => {
						let obj = {
							createtime: i.createtime,
							id: i.id,
							is_open: i.is_open,
							level: i.level,
							levelname: i.levelname,
							mobile: i.mobile,
							openid: i.openid,
							realname: i.realname,
							time: i.time,
							today_yeji: i.today_yeji,
							wx_num: i.wx_num,
							yeji: i.yeji,
							yx_num: i.yx_num,
							zsyj: i.zsyj,
							zyj: i.zyj,
							ChildList: [],
							isOpen: false
						}
						this.list.push(obj)
					})
				} else {
					data.user_list.forEach(item => {
						this.list[i].ChildList.push(item);
					})
				}








			},
			backFun() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss">
	.mineCommunity {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background-color: #F0EDF8;


		.mineCommunity_box {
			width: 100%;
			flex: 1;
			overflow-y: auto;

			.mineCommunity_box_scroll {
				width: 100%;
				// height: 200vh;

				.mineCommunity_box_scroll_top {
					width: 100%;
					height: 356rpx;
					background-color: #8D84FF;
					display: flex;
					align-items: flex-end;
					flex-direction: column;
					padding: 0 50rpx 95rpx 50rpx;

					.mineCommunity_box_scroll_top_centrer {
						width: 100%;
						height: 130rpx;
						display: flex;
						align-items: flex-end;
						color: #fff;

						.mineCommunity_box_scroll_top_centrer_image {
							width: 122rpx;
							height: 122rpx;
							border-radius: 122rpx;
							// background-color: #fff;
						}

						.mineCommunity_box_scroll_top_centrer_xinxis {
							flex: 1;
							height: 80%;
							display: flex;
							align-items: flex-end;
							padding-left: 20rpx;


							p {
								padding-left: 10rpx;
								font-size: 68rpx;
							}
						}

						.mineCommunity_box_scroll_top_centrer_xinxi {
							// width: 250rpx;
							height: 100%;
							// text-align: center;
							display: flex;
							flex-direction: column;
							// align-items: center;
							padding-left: 20rpx;
							justify-content: flex-end;
							color: #fff;

							p {
								font-size: 28rpx;

							}

							.mineCommunity_box_scroll_top_centrer_xinxi_dengji {
								width: 176rpx;
								height: 44rpx;
								border-radius: 44rpx;
								background-color: rgba(255, 255, 255, .6);
								margin-top: 18rpx;
								font-size: 28rpx;
								text-align: center;
								position: relative;

								.mineCommunity_box_scroll_top_centrer_xinxi_dengji_img {
									width: 36rpx;
									height: 36rpx;
									position: absolute;
									top: 3rpx;
									left: 10rpx;
									// background-color: #000;
									border-radius: 30rpx;
								}
							}
						}

						.mineCommunity_box_scroll_top_centrer_id {
							font-size: 28rpx;
							padding-left: 20rpx;
						}
					}
				}

				.mineCommunity_box_scroll_wodedingdan {
					width: 700rpx;
					height: 280rpx;
					margin: -50rpx auto 0 auto;
					background-color: #fff;
					border-radius: 20rpx;
					display: flex;
					flex-direction: column;

					.mineCommunity_box_scroll_wodedingdan_ {
						display: flex;
						width: 100%;
						height: 50%;
						justify-content: space-around;
						align-items: center;

						.mineCommunity_box_scroll_wodedingdan_item {
							width: 200rpx;
							text-align: center;
							color: #505050;
							font-size: 28rpx;
						}
					}
				}

				.mineCommunity_box_dictyosome {
					width: 100%;
					padding: 20rpx;

					.mineCommunity_box_dictyosome_item {
						width: 100%;
						min-height: 300rpx;
						padding: 20rpx;

						.mineCommunity_box_dictyosome_item_main {
							width: 100%;
							height: 300rpx;
							// margin: 20rpx 0;
							background-color: #fff;
							border-radius: 20rpx;

							.mineCommunity_box_dictyosome_item_main_top {
								width: 100%;
								height: 100rpx;
								display: flex;
								justify-content: space-between;
								padding: 0 30rpx;
								align-items: center;
								color: #856FFF;
								font-size: 26rpx;

								image {
									height: 50rpx;
								}
							}

							.mineCommunity_box_dictyosome_item_main_ {
								width: 100%;
								height: 80rpx;
								display: flex;
								justify-content: space-around;
								align-items: center;

								.mineCommunity_box_dictyosome_item_main_item {
									text-align: center;
									width: 200rpx;
									height: 80%;
									font-size: 26rpx;
									display: flex;
									flex-direction: column;
									justify-content: space-around;
								}
							}
						}

						.mineCommunity_box_dictyosome_item_null {
							width: 100%;
							height: 80rpx;
							line-height: 80rpx;

						}
					}
				}
			}
		}
	}
</style>